package com.zhiyou100.util;

import java.sql.*;

/**
 * jdbc 工具类
 *
 * @author yang
 * @version 1.0.0
 * @date 2020-09-11 10:20
 */
public class JdbcUtil {
    static {
        final String driverName = "oracle.jdbc.driver.OracleDriver";
        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("驱动类没有找到");
        }
    }

    public static Connection getConnection() {
        try {
            String url = "jdbc:oracle:thin:@localhost:1521:helowin";
            String user = "yang";
            String pwd = "123";
            return DriverManager.getConnection(url, user, pwd);
        } catch (SQLException throwables) {
            throw new RuntimeException("获取连接失败");
        }
    }

    public static void close(Connection con, ResultSet set, Statement sta) {
        try {
            if (set != null) {
                set.close();
            }
            if (sta != null) {
                sta.close();
            }
            if (con != null) {
                con.close();
            }
        } catch (Exception e) {
            throw new RuntimeException("关闭失败！");
        }
    }


}
